/** 
 
*/
import React, { PureComponent } from 'react';
import { TableC } from '@/src/comps';
import { Modal, message } from 'antd';
import { connect } from 'dva';
import config from '@/src/comps/business/tradingMarket/config';
import 'moment/locale/zh-cn';

const { confirm } = Modal;

class manualJudgment extends PureComponent {
  constructor(props) {
    super(props);
    this.state = {
      data: {
        pageInfo: {
          currentPage: 1,
          numInPage: 20,
        },
      },
    };
  }

  componentDidMount() {
    this.getList(this.props.searchData);
  }

  UNSAFE_componentWillReceiveProps(nextProps) {
    if (JSON.stringify(nextProps.searchData) != JSON.stringify(this.props.searchData)) {
      this.getList({ ...nextProps.searchData, currentPage: 1 });
    }
  }

  getList = (params) => {
    const { jrfs } = this.props;
    const {
      pageInfo: { currentPage, numInPage },
    } = this.state.data || {};
    this.props.dispatch({
      type: 'sppiTestRecordM/queryByPage',
      payload: {
        currentPage,
        numInPage,
        ...params,
        jrfs: jrfs,
      },
      callback: (res) => {
        if (res?.data) {
          this.setState({ data: res.data });
        }
      },
    });
  };

  //表格页码排序改变调用
  handleTableChange = (pagination) => {
    if (this.props.formReset) {
      message.warning('您已重置查询字段，请设置条件后执行查询');
      return;
    }
    const { current, pageSize } = pagination;
    this.getList({
      currentPage: current,
      numInPage: pageSize,
      ...this.props.searchData,
    });
  };

  getColumns = (columns) => {
    if (columns?.length > 0) {
      const newColumns = columns?.map((r) => {
        if (r.key == 'exchangecode') {
          return {
            ...r,
            width: 150,
            render: (t) => config.filter((x) => x.value == t)[0]?.title || '--',
          };
        }
        if (r.key == 'tradingcode') {
          return {
            ...r,
            width: 100,
          };
        }
        if (r.key == 'createdTs') {
          return {
            ...r,
            width: 120,
          };
        }
        if (r.key == 'sppijg') {
          return {
            ...r,
            width: 120,
            render: (t) => (t == '1' ? '通过' : t == '2' ? '不通过' : t == '3' ? '有条件通过' : '--'),
          };
        }
        return r;
      });
      return newColumns;
    }
    return;
  };
  render() {
    const { data = {} } = this.state;
    const { columns = [], dataSource = [], pageInfo } = data;

    return (
      <>
        <TableC
          columns={this.getColumns(columns)}
          dataSource={dataSource}
          loading={this.props.loading.effects['sppiTestRecordM/queryByPage']}
          rowKey='id'
          selfScrollY={true}
          current={pageInfo?.currentPage}
          pageSize={pageInfo?.numInPage}
          total={pageInfo?.total || 0}
          onChange={this.handleTableChange}
        ></TableC>
      </>
    );
  }
}
export default connect(({ sppiTestRecordM, loading }) => ({
  sppiTestRecordM,
  loading,
}))(manualJudgment);
